package com.kbbywyclient.ui.pop;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.kbbywyclient.R;

/**
 * Created by Jiangzx on 2017/8/18 13:39.
 */

public class SharePopWin extends PopupWindow {
    public static final int PLATFORM_WX =1;
    public static final int PLATFORM_WX_CIRCLE =2;
    public static final int PLATFORM_SINA =3;
    public static final int PLATFORM_QQ=4;

    public interface OnShare{
        void share(int platForm);
    }

    public SharePopWin(Context context,OnShare shareListener){
        setClippingEnabled(false);
        setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        setHeight(WindowManager.LayoutParams.MATCH_PARENT);
        View root=LayoutInflater.from(context).inflate(R.layout.pop_share,null);
        root.findViewById(R.id.iv_close).setOnClickListener(v->dismiss());
        RelativeLayout shareContainer= (RelativeLayout) root.findViewById(R.id.rl_share_container);
        int screenWidth=context.getResources().getDisplayMetrics().widthPixels;
        ViewGroup.LayoutParams layoutParams=shareContainer.getLayoutParams();
        //分享框的宽度/屏幕宽度 600:750
        int containerWidth= (int) (screenWidth*12/15.0f);
        layoutParams.width=containerWidth;
        layoutParams.height= (int) (containerWidth*1.2f);
        shareContainer.setLayoutParams(layoutParams);

        root.findViewById(R.id.ll_share_wx).setOnClickListener(v->{
            dismiss();
            if(shareListener!=null){
                shareListener.share(PLATFORM_WX);
            }
        });
        root.findViewById(R.id.ll_share_wx_circle).setOnClickListener(v->{
            dismiss();
            if(shareListener!=null){
                shareListener.share(PLATFORM_WX_CIRCLE);
            }
        });
        root.findViewById(R.id.ll_share_qq).setOnClickListener(v->{
            dismiss();
            if(shareListener!=null){
                shareListener.share(PLATFORM_QQ);
            }
        });
        root.findViewById(R.id.ll_share_sina).setOnClickListener(v->{
            dismiss();
            if(shareListener!=null){
                shareListener.share(PLATFORM_SINA);
            }
        });
        setContentView(root);
        setFocusable(true);
    }
}
